package com.hermes.comics.data;

import android.util.AndroidRuntimeException;

public enum IssueTag {
  SERIE_KEY("Serie key", 0),
  KEY("Key", 1),
  TITLE("Title", 2),
  URL("Url", 3),
  DATE("Date", 4),
  PAGES("Pages", 5),
  IMG("Picture", 6),
  MISSING("Missing", 7, true),
  READ("Read", 8, true);

  private String title;
  private int index;
  private boolean isBoolValue;

  private IssueTag(String title, int index) {
    this(title, index, false);
  }

  private IssueTag(String title, int index, boolean isBoolValue) {
    this.title = title;
    this.index = index;
    this.isBoolValue = isBoolValue;
  }

  public boolean isBoolValue() {
    return isBoolValue;
  }

  public int index() {
    return index;
  }

  public String title() {
    return title;
  }

  public String value(Issue issue) {
    return issue.getTagValue(this);
  }

  @Override
  public String toString() {
    return name().toLowerCase();
  }

  public static IssueTag getTagByString(String tagString) {
    try {
      return Enum.valueOf(IssueTag.class, tagString.toUpperCase());
    } catch (Exception e) {
      throw new AndroidRuntimeException("Tag " + tagString + " is not registered. See IssueTag.");
    }
  }
}
